﻿using System;
using System.Data.Entity;
using LibraryHub.Core.Models.LibraryOperation;
using LibraryHub.Core.Models.User;

namespace LibraryHub.DataAccess.EntityFramework
{
    public class DropCreateSeedDatabaseAlways : DropCreateDatabaseAlways<LibraryHubContext>
    {
        protected override void Seed(LibraryHubContext db)
        {
            db.Books.Add(new EfBook { Title = "book title 1", Description = "book description 1", IsTaken = true });
            db.Books.Add(new EfBook { Title = "book title 2", Description = "book description 2", IsTaken = true });
            db.Books.Add(new EfBook { Title = "book title 3", Description = "book description 3" });
            db.Books.Add(new EfBook { Title = "book title 4", Description = "book description 4" });
            db.Books.Add(new EfBook { Title = "book title 5", Description = "book description 5" });
            db.Books.Add(new EfBook { Title = "book title 6", Description = "book description 6" });
            db.Books.Add(new EfBook { Title = "book title 7", Description = "book description 7" });
            db.Books.Add(new EfBook { Title = "book title 8", Description = "book description 8" });
            db.Books.Add(new EfBook { Title = "book title 9", Description = "book description 9" });

            db.Users.Add(new EfUser { Login = "123", Password = "password1", FullName = "1", Role = (int)UserRoleEnum.Reader });
            db.Users.Add(new EfUser { Login = "1234", Password = "password1", FullName = "22", Role = (int)UserRoleEnum.Reader });
            db.Users.Add(new EfUser { Login = "12345", Password = "password1", FullName = "333", Role = (int)UserRoleEnum.Librarian });
            db.Users.Add(new EfUser { Login = "123456", Password = "password1", FullName = "4444", Role = (int)UserRoleEnum.Librarian });
            db.Users.Add(new EfUser { Login = "login5", Password = "password1", FullName = "full name 1", Role = (int)UserRoleEnum.Admin });
            db.Users.Add(new EfUser { Login = "login6", Password = "password1", FullName = "full name 1", Role = (int)UserRoleEnum.Admin });
            db.Users.Add(new EfUser { Login = "login7", Password = "password1", FullName = "full name 1", Role = (int)UserRoleEnum.Admin });

            db.Users.Add(new EfUser { Login = "admin", Password = "admin", FullName = "admin name", Role = (int)UserRoleEnum.Admin });
            db.Users.Add(new EfUser { Login = "librarian", Password = "librarian", FullName = "librarian name", Role = (int)UserRoleEnum.Librarian });
            db.Users.Add(new EfUser { Login = "reader", Password = "reader", FullName = "reader name", Role = (int)UserRoleEnum.Reader });

            db.SaveChanges();

            db.Operations.Add(new EfLibraryOperation
                                  {
                                      OperationType = (int)LibraryOperationEnum.TakeBook,
                                      OperationValue = 4,
                                      EfUserId = 1,
                                      EfBookId = 1,
                                      OperationDate = DateTime.Now
                                  });
            db.Operations.Add(new EfLibraryOperation
                                  {
                                      OperationType = (int)LibraryOperationEnum.TakeBook,
                                      OperationValue = 13,
                                      EfUserId = 2,
                                      EfBookId = 2,
                                      OperationDate = DateTime.Now
                                  });

            db.SaveChanges();

        }
    }
}